// Agent robot in project robot.mas2j

/* Initial beliefs and rules */

/* Initial goals */

!goToDestination.

/* Plans */

+!goToDestination : true
	<- .puts("Moving to Destination");
		move(forward,0.5);move(backward,0.5);
		.puts("Arriving at destination").

-!goToDestination[R1 | Rest] : triedAlone
	<- .puts("Cannot solve problem alone, communicating with robotHelper");
		.broadcast(achieve,helpme).
	
-!goToDestination[R1 | Rest] : true
	<- .puts("#{R1} #{Rest}");
		!diagnoseAlone([R1| Rest]);
		!goToDestination.

+!diagnoseAlone(Reasons) : .member(no_progress,Reasons) & .member(error_msg(M),Reasons)
	<- .puts("Running local diagnostics");
		.puts("diagnose alone has failed");
		+triedAlone;
		.puts("Agent is blocked and moved #{M}");
		.puts("Finished diagnostics").

		
//Plans to help diagnose
+!tryMove[source(R)] : true
	<-  .puts("Trying to bit for #{R}");
		!!testMove(backward,0.2);
		.wait(2000);
		.send(R,tell,moved(0.2)).
		  
+!testMove(D,Dis) : true
	<- .puts("Moving a bit for #{R}");
		move(D,Dis).

+found(Me)[source(R)] : .my_name(Me)
	<- .puts("#{R} found me, asking to track me");
	   .send(R,achieve,trackMe).
